import json
from binascii import b2a_hex, a2b_hex
from django.shortcuts import HttpResponse

RESULT_SUCCESS = 'SUCCESS'
RESULT_FAIL = 'FAIL'
ERROR_INFO = 'error_info'
PARAMETER_ERROR = 'parameters is not ok'
DELETE_ERROR = 'An error occurred while deleting the record'

def result(code, msg, data=None):
    re = Result()
    re.code = code
    re.msg = msg
    re.data = data

    return json.dumps(re, default=dic)


def resp_result(code, msg, data=None):
    return HttpResponse(result(code, msg, data))


def dic(obj):
    if type(obj) is dict:
        return obj
    elif type(obj) is bytes:
        return obj.decode()
    else:
        return obj.__dict__

class Result:
    code = 1
    msg = ''
    data = None


# print(result(1, RESULT_SUCCESS, {'key': 'test'}))

# print(type({'key': 'jfdjs'}) is dict)


# print(result(1, 'success'))
# print(result(1, 'hhahahah', {'name': 'wang'}))
